import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store/index.js";

import axios from "axios";

import request from "@/utils/request.js";
import requestTools from "@/utils/request-tools.js";

// 封装fetch请求绑定在原型上
Vue.prototype.$request = request;

// 封装的 await axios
Vue.prototype.$requestTools = requestTools;

Vue.prototype.$axios=axios;


// 导入搜索框 轮播图 grid等~
import {
  Search,
  Icon,
  Loading,
  TreeSelect,
  Swipe,
  SwipeItem,
  Grid,
  GridItem,
  Sticky,
  NavBar,
  Popover,
  Button,
  CellGroup,
  field,
  GoodsAction,
  GoodsActionIcon,
  GoodsActionButton ,
} from "vant";
Vue.use(Search);
Vue.use(Icon);
Vue.use(Loading);
Vue.use(TreeSelect);
Vue.use(Sticky);
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Grid);
Vue.use(GridItem);
Vue.use(NavBar);
Vue.use(Popover);
Vue.use(Button);
Vue.use(CellGroup);
Vue.use(field);
// Vue.vue(Field);
Vue.use(GoodsAction);
Vue.use(GoodsActionIcon);
Vue.use(GoodsActionButton);
import { Sku } from 'vant';

Vue.use(Sku);
import { ActionSheet } from 'vant';

Vue.use(ActionSheet);

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

// 不需要携带token的接口
// const noislogin = [
//   "/crmeb/product/hot",
//   "/crmeb/index",
//   "/crmeb/index/product/",
//   "/crmeb/seckill/index",
//   "/crmeb/product/leaderboard",
//   "/crmeb/combination/index",
//   "/crmeb/category",
//   "/crmeb/products",
//   "/crmeb/product/sku/detail",
//   "/crmeb/login",
// ];
axios.interceptors.request.use(
  (config) => {
    // console.log(config);
    if(sessionStorage.getItem('token')){
      config.headers["authori-zation"] = sessionStorage.getItem("token");
    }
    
    // const requestUrl = config.url; //当前访问的接口地址，在config里可以查看到
    // const is_login = noislogin.findIndex((path) => requestUrl.includes(path));
    // if (is_login !== -1) {
    //   // console.log(`${requestUrl}不需要携带token`);
    // } else {
    //   // console.log(`${requestUrl}需要携带token`);
      
    // }

    return config;
  },

  (error) => {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);